/**
 * Copyright (c) 2009 Teoti Graphix, LLC See:
 *     http://tkarchitecture.teotigraphix.org
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * @author Michael Schmalle mschmalle@teotigraphix.com
 */
package com.example.acme
{

import com.example.acme.controller.command.StartupCommand;

import org.puremvc.as3.multicore.patterns.facade.Facade;

/**
 * The main application facade.
 * 
 * @author Michael Schmalle
 * @copyright Teoti Graphix, LLC
 */
public class ApplicationFacade extends Facade
{
	//--------------------------------------------------------------------------
	//
	//  Public Class Notifications :: Constants
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Starts the application and executes startup commands.
	 */	
	public static const STARTUP:String 	= 'startup';
	
	/**
	 * Notifies the framework to login in the user.
	 * 
	 * @body A User instance holding login credentials.
	 */
	public static const USER_LOGIN:String = 'userLogin';
	
	/**
	 * Notifies the framework the login is complete and advance the application's
	 * current state.
	 * 
	 * @body A logged in User instance.
	 */
	public static const USER_LOGIN_COMPLETE:String = 'userLoginComplete';
	
	/**
	 * Notifies the framework the login has faulted.
	 *  
	 * @body 
	 */
	public static const USER_LOGIN_FAULT:String = 'userLoginFault';	
	
	//--------------------------------------------------------------------------
	//
	//  Constructor
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Creates a new <code>User</code> instance.
	 * 
	 * @param key The application's name.
	 */
	public function ApplicationFacade( key:String )
	{
		super( key );
	}
	
	//--------------------------------------------------------------------------
	//
	//  Overridden Protected :: Methods
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Registers the <code>StartupCommand</code> with the controller.
	 */
	override protected function initializeController():void 
	{
		super.initializeController();
					
		registerCommand( STARTUP, StartupCommand );
	}
	
	//--------------------------------------------------------------------------
	//
	//  Public API :: Methods
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Application startup.
	 * 
	 * @param app a Reference to the main application component.
	 * @note #STARTUP
	 */  
	public function startup( app:LoginApplication ):void
	{
		sendNotification( STARTUP, app );
	}
	
	//--------------------------------------------------------------------------
	//
	//  Public Class :: Methods
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Creates and returns the single instance of the ApplicationFacade.
	 * 
	 * @param key The application's name.
	 * @return The single instance of the ApplicationFacade.
	 */
	public static function getInstance( key:String ):ApplicationFacade 
	{
		if (instanceMap[ key ] == null) 
			instanceMap[ key ] = new ApplicationFacade( key );
		
		return instanceMap[ key ] as ApplicationFacade;
	}	
}
}